Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #276 +/- ##
=======================================
Coverage 95.89% 95.89%
=======================================
Files 5 5
Lines 463 463
=======================================
Hits 444 444
Misses 19 19
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
…l_name make_valid_xml_name was calling escape_xml(key) and storing the escaped value. Later, make_attr_string would escape it again, producing output like name="tag&amp;name" instead of name="tag&name". Now make_valid_xml_name operates on the raw key and lets make_attr_string handle the single escaping pass. Amp-Thread-ID: https://ampcode.com/threads/T-019ce197-0f45-7644-a010-590c20704f18 Co-authored-by: Amp <amp@ampcode.com>
Rust's f64::to_string() renders 1.0 as "1" while Python gives "1.0". Since this is a drop-in replacement for the Python dicttoxml, use obj.str() to get Python's native float representation. Amp-Thread-ID: https://ampcode.com/threads/T-019ce197-0f45-7644-a010-590c20704f18 Co-authored-by: Amp <amp@ampcode.com>
The try_iter() path used filter_map(|r| r.ok()) which silently dropped any exceptions raised during iteration. Now uses collect::<PyResult<_>>()? to properly propagate errors to the caller. Amp-Thread-ID: https://ampcode.com/threads/T-019ce197-0f45-7644-a010-590c20704f18 Co-authored-by: Amp <amp@ampcode.com>
Previously custom_root was written directly into XML tags without validation, allowing arbitrary strings to produce invalid XML output. Now raises ValueError for invalid root element names. Amp-Thread-ID: https://ampcode.com/threads/T-019ce197-0f45-7644-a010-590c20704f18 Co-authored-by: Amp <amp@ampcode.com>
…el escaping
Major restructuring of the Rust extension:
- Collapsed three identical type-dispatch chains (convert_value,
convert_dict, convert_list) into a single write_value() function.
Removes ~300 lines of duplicated if/else logic.
- All XML writing now appends to a single shared String buffer via
write_value/write_dict_contents/write_list_contents instead of
allocating intermediate Strings at every recursion level.
- Replaced char-by-char escape_xml with byte-scanning push_escaped_text
(for text nodes, only escapes &<>) and push_escaped_attr (for
attributes, also escapes quotes). Copies clean slices in bulk.
- Replaced format!-based wrap_cdata with push_cdata that writes
directly to the buffer without intermediate allocations.
- Replaced to_lowercase().starts_with("xml") in is_valid_xml_name
with eq_ignore_ascii_case to avoid allocating a lowercased copy.
- Removed unused std::fmt::Write import, added #[derive(Copy, Clone)]
to ConvertConfig, gated helper functions behind cfg(python).
- Added tests for push_escaped_text, push_escaped_attr, push_cdata.
Amp-Thread-ID: https://ampcode.com/threads/T-019ce197-0f45-7644-a010-590c20704f18
Co-authored-by: Amp <amp@ampcode.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pyo3 0.28.2and bump the Rust package version to0.2.0What changed
name="..."attributesstr()for float rendering so values like1.0preserve Python-compatible formattingtry_iter()custom_rootand raiseValueErrorfor invalid XML element nameswrite_value,write_dict_contents,write_list_contents)Validation